﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Kexp.ShoutcastRunner.Tests
{
	[TestClass]
	public class TestShoutcastLogParser
	{
		private const string TestLine1 = "<09/05/12@13:00:09> [source] listening for connection on port 8001";
		private const string TestLine2 = "<09/05/12@13:00:57> [dest: 11.111.11.11] starting stream (UID: 11)[L: 7]{A: Roku/DVP-4.8 (024.08E01184A)}(P: 7)";
		private const string TestLine3 = "<10/05/12@09:12:48> [dest: 111.111.111.11] starting stream (UID: 46096)[L: 146]{A: kexp-radio/2.0 CFNetwork/609 Darwin/13.0.0}(P: 122)";

		[TestMethod]
		public void Line_GetDate_WorksCorrectly()
		{
			var line = new ShoutcastLogParser.Line(TestLine1);
			Assert.AreEqual(new DateTime(2012, 9, 5, 13, 0, 9), line.GetDate());

			line = new ShoutcastLogParser.Line(TestLine2);
			Assert.AreEqual(new DateTime(2012, 9, 5, 13, 0, 57), line.GetDate());

			line = new ShoutcastLogParser.Line(TestLine3);
			Assert.AreEqual(new DateTime(2012, 10, 5, 9, 12, 48), line.GetDate());
		}

		[TestMethod]
		public void ParseDailyLogs_GiventRegularLog_WorksAsExpected()
		{
			string testFile = @"c:\test\shoutcast\sc_serv.log";
			Assert.IsTrue(ShoutcastLogParser.ParseDailyLogs(testFile));
		}

		[TestMethod]
		public void ParseDailyLogs_GivenW3CLog_ReturnsFalse()
		{
			string testFile = @"c:\test\shoutcast\sc_w3c.log";
			Assert.IsFalse(ShoutcastLogParser.ParseDailyLogs(testFile));
		}
	}
}
